package gui;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import javax.swing.JLabel;

import logic.Facade;
import logic.ToGuiFacade;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class pnlUserPanel extends javax.swing.JPanel {
	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private JButton changePersonalDetailsButton;
	private JButton rateMovieButton;
	private JLabel lblNewUser2;
	private JLabel lblNewUser;
	private JButton backButton;
	private JButton btnAddMovie;
	private JButton btnDeleteUser;
	private JButton btnDeleteMovie;
	private JLabel jCustomText;
	private JLabel picLabel;
	private JButton getRecommendationButton;
	private JLabel userNameLabel;
	private JLabel headLineLabel;

	public pnlUserPanel(String user, boolean admin){
		super();
		initGUI(user, null);
		if (admin){
			addAdminButtons(user);
		}
	}

	public pnlUserPanel(String user, boolean admin, String message){
		super();
		initGUI(user, message);
		if (admin){
			addAdminButtons(user);
		}
	}


	private void initGUI(final String user , String message) {
		try {
			this.setPreferredSize(new java.awt.Dimension(793, 549));
			this.setSize(793, 549);
			this.setLayout(null);
			this.setBackground(new java.awt.Color(255,128,0));
			{
				headLineLabel = new JLabel();
				this.add(headLineLabel);
				headLineLabel.setText("<html><u>My Profile</u></html>");
				headLineLabel.setBounds(148, 22, 146, 39);
				headLineLabel.setFont(new java.awt.Font("Arial",1,26));
				headLineLabel.setForeground(new java.awt.Color(0,128,192));
			}
			{
				userNameLabel = new JLabel();
				this.add(userNameLabel);
				userNameLabel.setText(user);
				userNameLabel.setBounds(312, 30, 117, 25);
				userNameLabel.setForeground(new java.awt.Color(0,128,192));
				userNameLabel.setFont(new java.awt.Font("Arial",1,20));
			}
			{
				changePersonalDetailsButton = new JButton();
				this.add(changePersonalDetailsButton);
				changePersonalDetailsButton.setText("Change my personal details");
				changePersonalDetailsButton.setBounds(109, 149, 215, 30);
				changePersonalDetailsButton.setSize(215, 27);
				changePersonalDetailsButton.addActionListener(new ActionListener(){
					public void actionPerformed(ActionEvent e){
						ToGuiFacade.getInstance().showChangeDetailsScreen(user);
					}
				});
			}
			{
				rateMovieButton = new JButton();
				this.add(rateMovieButton);
				rateMovieButton.setText("I want to rate a movie");
				rateMovieButton.setBounds(109, 203, 215, 27);
				rateMovieButton.addMouseListener(new MouseAdapter() {
					public void mouseReleased(MouseEvent evt) {
						ToGuiFacade fac= ToGuiFacade.getInstance();
						fac.changeScreen(new pnlRecommendationList(user));
					}
				});
			}
			{
				getRecommendationButton = new JButton();
				this.add(getRecommendationButton);
				getRecommendationButton.setText("What movies should I watch?");
				getRecommendationButton.setBounds(109, 252, 215, 27);
				getRecommendationButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ToGuiFacade fac= ToGuiFacade.getInstance();
						fac.changeScreen(new pnlRecommendation(user));
					}
				});
			}
			{
				backButton = new JButton();
				this.add(backButton);
				backButton.setText("back");
				backButton.setBounds(701, 482, 72, 21);
				backButton.addMouseListener(new MouseAdapter() {
					public void mouseReleased(MouseEvent evt) {
						ToGuiFacade fac= ToGuiFacade.getInstance();
						fac.back();
					}
				});
			}
			{
				picLabel = new JLabel();
				this.add(picLabel);
				picLabel.setIcon(new ImageIcon(getClass().getClassLoader().getResource("documentation/Secret4PlusDog.jpg")));
				picLabel.setBounds(553, 30, 220, 407);
			}
			if (message!=null)
			{
				jCustomText = new JLabel();
				this.add(jCustomText);
				jCustomText.setText(message);
				jCustomText.setBounds(214, 444, 245, 14);
			}
			int numRatings = Facade.getInstance().getNumRating(user);
			if (numRatings < 10){
				{
					lblNewUser = new JLabel();

					this.add(lblNewUser);
					lblNewUser.setText("New user:  You need to rate " + (10-numRatings) + " more movies");
					lblNewUser.setBounds(27, 78, 437, 41);
					lblNewUser.setFont(new java.awt.Font("Tahoma",1,14));
					lblNewUser.setForeground(new java.awt.Color(0,128,255));
				}
				{
					lblNewUser2 = new JLabel();
					this.add(lblNewUser2);
					lblNewUser2.setText("for the system to efficiently recommend for you");
					lblNewUser2.setFont(new java.awt.Font("Tahoma",1,14));
					lblNewUser2.setForeground(new java.awt.Color(0,128,255));
					lblNewUser2.setBounds(27, 109, 432, 41);
				}
				{
					//rateMovieButton.setBackground(Color.GREEN);
					rateMovieButton.setForeground(Color.GREEN);
				}
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void addAdminButtons(final String user){
		{
			btnDeleteMovie = new JButton();
			this.add(btnDeleteMovie);
			btnDeleteMovie.setText("Delete a movie");
			btnDeleteMovie.setBounds(109, 301, 215, 27);
			btnDeleteMovie.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					ToGuiFacade.getInstance().showDeleteMovieScreen(user);
				}
			});
		}
		{
			btnDeleteUser = new JButton();
			this.add(btnDeleteUser);
			btnDeleteUser.setText("Delete a user");
			btnDeleteUser.setBounds(109, 350, 215, 27);
			btnDeleteUser.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					ToGuiFacade.getInstance().showDeleteUserScreen(user);
				}
			});
		}

		{
			btnAddMovie = new JButton();
			this.add(btnAddMovie);
			btnAddMovie.setText("Add a movie");
			btnAddMovie.setBounds(109, 398, 215, 27);
			btnAddMovie.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					ToGuiFacade.getInstance().showAddMovieScreen(user);
				}
			});
		}


	}

}
